package lx;

import java.io.*;
import java.util.*;

/*
       需求：把《出师表》的文章顺序进行恢复到一个新文件中。
  */
public class demo2Case3 {
    public static void main(String[] args) throws IOException {
        //1.读取数据
        BufferedReader br = new BufferedReader(new FileReader("a.txt"));

        //键是序号，值是内容
        TreeMap<Integer, String> tm = new TreeMap<>();
        String s;
        while ((s = br.readLine()) != null) {
            String[] arr = s.split("\\.");
            //0：序号  1 ：内容
            //s代表每一行数据
            tm.put(Integer.parseInt(arr[0]), s);
        }
        br.close();

        //2.写出数据
        BufferedWriter bw = new BufferedWriter(new FileWriter("b.txt"));
        Set<Map.Entry<Integer, String>> entries = tm.entrySet();
        for (Map.Entry<Integer, String> entry : entries) {
            String value = entry.getValue();
            bw.write(value);
            bw.newLine();
        }
        bw.close();

    }
}
